/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.netbeans.modules.project.dependency.spi;

import java.util.Collection;
import java.util.List;
import javax.swing.event.ChangeListener;
import org.netbeans.api.project.Project;
import org.netbeans.modules.project.dependency.ArtifactSpec;
import org.netbeans.modules.project.dependency.ProjectArtifactsQuery;

/**
 *
 * @author sdedic
 */
public interface ProjectArtifactsImplementation<Result> {
    /**
     * Finds project artifact(s) that match the query. The implementation should
     * compute data and store it into implementation-defined Result data structure,
     * which will be used during subsequent calls.
     * 
     * @param query the query to answer
     * @return result structure.
     */
    public Result evaluate(ProjectArtifactsQuery.Filter query);

    /**
     * Returns evaluation order of this Implementation. Implementations ordered
     * later may remove artifacts generated by earlier ones.
     * 
     * @return order of the implementation.
     */
    public default int getOrder() {
        return 10000;
    }
    
    /**
     * Returns the project instance for the result
     * @param r result
     * @return project instance
     */
    public Project findProject(Result r);
    
    /**
     * @return Reports project artifacts.
     */
    public List<ArtifactSpec> findArtifacts(Result r);
    
    /**
     * If not null, specifies artifacts to be excluded from the final result. For example
     * a transformation plugin may rename the original artifact so that the original place
     * is empty.
     * @return excluded artifacts, or {@code null}.
     */
    public Collection<ArtifactSpec> findExcludedArtifacts(Result r);
    
    /**
     * Adds or removes a listener on the result
     * @param r the result
     * @param l the listener
     * @param add true to add, false to remove
     */
    public void handleChangeListener(Result r, ChangeListener l, boolean add);
    
    /**
     * Determines if the result supports changes. Results that do not support changes never
     * fire change events.
     * @param r the result
     * @return true, if the result supports changes.
     */
    public boolean computeSupportsChanges(Result r);
}
